﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace VatGia
{
    public partial class FormMain1 : Form
    {
        public FormMain1()
        {
            InitializeComponent();
        }
        
        private void btnDK_Click(object sender, EventArgs e)
        {
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            load();
        }

        private void FormMain1_Load(object sender, EventArgs e)
        {
            load();
        }
        public void load()
        {
            if (Public_variable.Username != "")
            {
                lbhello.Dock = DockStyle.Right;
                lbhello.Text = "Xin chào "+ Public_variable.Hoten;
                lbhello.Visible = true;
                btnLogin.Text = "Logout";
                btnRegester.Visible = false;
            }
            if (Public_variable.Giohang.Count > 0)
            {
                lbhello.Text += " - Bạn đã chọn "+ Public_variable.Giohang.Count.ToString()+ " sản phẩm";
            }
            splitContainer1.Panel2.Controls.Clear();
            FormSanPham frm = new FormSanPham(this);
            frm.TopLevel = false;
            frm.Dock = DockStyle.Fill;
            //frm.ShowForm += new ShowFromChiTiet(frm_ShowForm);
            splitContainer1.Panel2.Controls.Add(frm);

            frm.Show();
        }
        public void frm_ShowFormSP()
        {
            if (Public_variable.Giohang.Count > 0)
            {
                if (Public_variable.Username == "")
                {
                    lbhello.Visible = true;
                    lbhello.Text = "Bạn đã chọn " + Public_variable.Giohang.Count.ToString() + " sản phẩm";

                }
                else
                {
                    lbhello.Visible = true;
                    lbhello.Dock = DockStyle.Right;
                    lbhello.Text = "Xin chào " + Public_variable.Hoten + "Bạn đã chọn " + Public_variable.Giohang.Count.ToString() + " sản phẩm";
                }
            }
            splitContainer1.Panel2.Controls.Clear();
            FormSanPham frm = new FormSanPham(this);
            frm.TopLevel = false;
            frm.Dock = DockStyle.Fill;
            splitContainer1.Panel2.Controls.Add(frm);

            frm.Show();
        }

        private void btnRegester_Click(object sender, EventArgs e)
        {
            splitContainer1.Panel2.Controls.Clear();
            FormDangKy frm = new FormDangKy(this);
            frm.TopLevel = false;
            frm.Dock = DockStyle.Fill;
            splitContainer1.Panel2.Controls.Add(frm);

            frm.Show();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            //
            if (Public_variable.Username == "")
            {
                splitContainer1.Panel2.Controls.Clear();
                FormDangNhap frm = new FormDangNhap(this);
                frm.TopLevel = false;
                frm.Dock = DockStyle.Fill;
                
                splitContainer1.Panel2.Controls.Add(frm);

                frm.Show();
            }
            else  // khi bam logout
            {
                Public_variable.Username = "";
                Public_variable.Hoten = "";
                lbhello.Text = "";
                btnLogin.Text = "Login";
                btnRegester.Visible = true;
                load();
            }
        }

        void frm_Showfromsp()
        {
            load();
        }
       
        private void btnQLGianHang_Click_1(object sender, EventArgs e)
        {
            if (Public_variable.Username != "")
            {
                splitContainer1.Panel2.Controls.Clear();
                FormQLGianHang frm = new FormQLGianHang(this);
                frm.TopLevel = false;
                frm.Dock = DockStyle.Fill;
                splitContainer1.Panel2.Controls.Add(frm);

                frm.Show();
            }else{
                MessageBox.Show("Vui lòng đăng nhập");
            }
        }

        private void btnTimKiem_Click(object sender, EventArgs e)
        {
            splitContainer1.Panel2.Controls.Clear();
            FormTimKiem frm = new FormTimKiem(this);
            frm.TopLevel = false;
            frm.Dock = DockStyle.Fill;
            
            splitContainer1.Panel2.Controls.Add(frm);

            frm.Show();
        }

       public  void frm_ShowFormChiTiet()
        {
            splitContainer1.Panel2.Controls.Clear();
            FormChiTietSanPham frm = new FormChiTietSanPham(this);
            frm.TopLevel = false;
            frm.Dock = DockStyle.Fill;
            
            splitContainer1.Panel2.Controls.Add(frm);

            frm.Show();
        }

        private void btnQLTinNhan_Click(object sender, EventArgs e)
        {
            if (Public_variable.Username != "")
            {
                splitContainer1.Panel2.Controls.Clear();
                FormQLTinNhan frm = new FormQLTinNhan();
                frm.TopLevel = false;
                frm.Dock = DockStyle.Fill;
                splitContainer1.Panel2.Controls.Add(frm);

                frm.Show();
            }
            else
            {
                MessageBox.Show("Vui lòng đăng nhập");
            }
        }

        private void btnQLSanPham_Click(object sender, EventArgs e)
        {
            if(Public_variable.Username!="")
            {
                splitContainer1.Panel2.Controls.Clear();
                FormQLSanPham frm = new FormQLSanPham(this);
                frm.TopLevel = false;
                frm.Dock = DockStyle.Fill;
                splitContainer1.Panel2.Controls.Add(frm);

                frm.Show();
            }
            else{
                MessageBox.Show("Vui lòng đăng nhập");
            }
        }
        public void frm_ShowFormGianHang()
        {
            splitContainer1.Panel2.Controls.Clear();
            FormQLGianHang frm = new FormQLGianHang(this);
            frm.TopLevel = false;
            frm.Dock = DockStyle.Fill;
            splitContainer1.Panel2.Controls.Add(frm);

            frm.Show();
        }

        public void frm_ShowFormGioHang()
        {
            splitContainer1.Panel2.Controls.Clear();
            FormGioHang frm = new FormGioHang(this);
            frm.TopLevel = false;
            frm.Dock = DockStyle.Fill;
            splitContainer1.Panel2.Controls.Add(frm);

            frm.Show();
        }

        private void btnGioHang_Click(object sender, EventArgs e)
        {
            if (Public_variable.Giohang.Count > 0)
            {
                splitContainer1.Panel2.Controls.Clear();
                FormGioHang frm = new FormGioHang(this);
                frm.TopLevel = false;
                frm.Dock = DockStyle.Fill;
                splitContainer1.Panel2.Controls.Add(frm);

                frm.Show();
            }
            else {
               // MessageBox.Show("Chưa có sản phẩm nào trong giỏ hàng !");
                splitContainer1.Panel2.Controls.Clear();
                FormGioHang frm = new FormGioHang(this);
                frm.TopLevel = false;
                frm.Dock = DockStyle.Fill;
                splitContainer1.Panel2.Controls.Add(frm);

                frm.Show();
            }
        }

        private void btnindex_Click(object sender, EventArgs e)
        {
            
            if (btnindex.Text == "index")
            {
                btnindex.Text = "Non Index";
                Public_variable.Dbname = "VatGia_NonIndex";
            }
            else {
                btnindex.Text = "index";
                Public_variable.Dbname = "VatGia";
            }
        }
    }
}
